package operation;


import book.Book;
import book.BookList;

import java.util.Scanner;

public class DelOperation implements IOperation{
    public void work(BookList bookList) {
        System.out.println("删除图书===");
        System.out.println("请输入书名：");
        Scanner scanner = new Scanner(System.in);
        String name = scanner.nextLine();
        int current = bookList.getUseSize();
        int i = 0;
        int index = -1;
        for (; i < current; i++) {
            Book book = bookList.getBook(i);
            if(name.equals(book.getName())){
                index = i;
                break;
            }
        }
        if(i>=current){
            System.out.println("没有该图书===");
            return;
        }
        for (int j = index; j < current -1; j++) {
            Book book = bookList.getBook(j + 1);
            bookList.setBooks(j,book);
        }
        bookList.setUseSize(current - 1);

    }
}
